﻿using System;
using System.Windows.Forms;
using BuildStatusIndicator.BuildScreen;
using BuildStatusIndicator.Controller;
using BuildStatusIndicator.Controller.EventBroker;
using BuildStatusIndicator.DelCom;
using BuildStatusIndicator.X10;
using Microsoft.Practices.Unity;

namespace BuildStatusIndicator
{
    internal static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            IUnityContainer container = new UnityContainer();

            Configuration.ContainerConfiguration(container);

            SetupPublisher(container);
            SetupSubscribers(container);

            using (var controller = container.Resolve<IController>())
            {
                controller.Connect();
                var presenter = container.Resolve<BuildScreenPresenter>();
                Application.Run((Form) presenter.View);
                controller.Disconnect();
            }
        }

        private static void SetupPublisher(IUnityContainer container)
        {
            container.Resolve<BuildStatusEventPublisher>();
        }

        private static void SetupSubscribers(IUnityContainer container)
        {
            container.Resolve<DelComBuildIndicator>();
            container.Resolve<X10BuildIndicator>();
        }
    }
}